package org.example.config;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnel;
import com.google.common.hash.Funnels;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
public class MyBloomFilter {

    public BloomFilter<Long> bloomFilter;
    private static final long SIZE = 100;       //设置长度为多少 用来判断是否存在

    @EventListener
    public void contextRefreshedEventListener(ContextRefreshedEvent contextRefreshedEvent){
        bloomFilter = BloomFilter.create(Funnels.longFunnel(), SIZE);
        for (long i = 1; i <= SIZE ; i++){
            bloomFilter.put(i);
        }
    }

}
